#include "Locker.h"
//
EventLock::EventLock() {
	_handle = CreateEvent(NULL, FALSE, TRUE, 0);
}
//
EventLock::~EventLock() {
	CloseHandle(_handle);
}
//
void EventLock::lock() {
	WaitForSingleObject(_handle, INFINITE);
}
//
bool EventLock::tryToLock() {
	return WaitForSingleObject(_handle, 0) == WAIT_OBJECT_0;
}
//
void EventLock::unlock() {
	SetEvent(_handle);
}
//
//
CriticalSectionLock::CriticalSectionLock() {
	InitializeCriticalSection(&_cs);
}
//
CriticalSectionLock::~CriticalSectionLock() {
	DeleteCriticalSection(&_cs);
}
//
void CriticalSectionLock::lock() {
	EnterCriticalSection(&_cs);
}
//
bool CriticalSectionLock::tryToLock() {
	return TryEnterCriticalSection(&_cs) == TRUE;
}
//
void CriticalSectionLock::unlock() {
	LeaveCriticalSection(&_cs);
}
